<template>
  <div>
    <div v-if=" commodityInfo && commodityInfo.lastStockCountNum >0 "
         class="aui-btn aui-btn-danger aui-btn-sm add_to_cart"
         style="padding:0 0.7rem;height: 100%;bottom: 0;position:absolute;z-index: 1;right: 0;line-height: 3rem;font-size:1rem;border-radius: 0"
         @click="showCartModle">
      {{isDetailFood?'加入餐盘':'加入购物车'}}
    </div>
    <div v-if="commodityInfo.lastStockCountNum <= 0"
         class="aui-btn aui-btn-sm add_to_cart"
         style="color:white;background: #ddd ;height: 100%;bottom: 0;position:absolute;z-index: 1;right: 0;line-height: 3rem;font-size: 1rem;border-radius: 0;padding:0 0.7rem;">
      已售罄
    </div>

    <cart-mode ref="cartModle" buttonText="确 定" @isClossing="updateCart" :height="'auto'">
      <add-cart-for-proce v-if="commodityInfo && !isDetailFood" ref="addCartForProce" 
                          :commodityInfor="commodityInfo"  @Closing="hideShade">
      </add-cart-for-proce>
      <add-cart-for-food v-if="commodityInfo && isDetailFood" ref="addCartForProce" :commodityInfor="commodityInfo" @Closing="hideShade">
      </add-cart-for-food>
    </cart-mode>

  </div>
</template>

<script>
  // import Hello from './components/Hello'
  import {mapState, mapGetters} from 'vuex'
  import CartMode from '../CartMode';
  import AddCartForProce from '../AddCartForProce'
  import AddCartForFood from '../AddCartForProce/forFoods.vue'
  import UpdateCart from '../UpdateCart'
  import {translateDetailData, getLastStockCountNum} from '@/utils/TranslateDetailDate';
  import getConfig from '@/utils/CJY/getConfig';

  export default {
    data() {
      return {
        workingInfo: null
      }
    },
    props: {
      goodsInfo: {
        type: Object,
        default: () => ({})
      },
      isDetailFood: {
        type: Boolean,
        default: false
      },
      isShare: {
      	default: 0
      }
    },
    components: {CartMode, AddCartForProce,AddCartForFood},
    methods: {
      translateDetailData,
      async showCartModle() {
      	if(this.isShare) {
	      	   this.$router.push({
							name: "MiddleWare",
						})
              return
				}
        if (this.storeConfigStatus == 'loaded') {
        } else if (this.storeConfigStatus == 'loading') {
          return
        } else {
          await getConfig()
          if (this.storeConfigStatus != 'loaded') {
            return
          }
        }
        var islocal = (/^localhost:8082+/gi).test(location.host) || this.goodsTrolleyType
        var isXiangpu = navigator.userAgent.indexOf("xiangpu") > -1;         //判断是否在象谱内打开
        if (!isXiangpu && !islocal) {
          location.href = location.href.split('H5')[0] + 'download/index.html';
          return
        }
        // this.workingInfo || this.getWorkingInfo()
        this.$refs.cartModle && this.$refs.cartModle.showModle();
      },

      async getWorkingInfo() {
      },

      updateCart() {
        this.$refs.addCartForProce && this.$refs.addCartForProce.updateCart()
      },
      hideShade() {
        console.log('cccccc')
        this.$refs.cartModle.isShow = false;
      }
    },

    mounted() {
      console.log(this.isDetailFood,'isDetailFood')
    },
    computed: {
      ...mapGetters({
        userInfo: 'xhModules/userInfo',
        sessionId: 'xhModules/sessionId',
      }),
      ...mapGetters(['cartConfig', 'storeConfigStatus']),
      goodsTrolleyType() {
        var getConfigParams = this.cartConfig || {}
        return getConfigParams.goodsTrolleyType || 0
      },
      commodityInfo() {
        return translateDetailData(this.goodsInfo)
      }
    }
  }
</script>

<style>

</style>
